package LogBook;

public class Frequency {
	private double frequency;

	public Frequency() {
		this.frequency = 0;
	}

	public Frequency(int frequency) {
		this.frequency = frequency;
	}

	public Frequency(String frequency) {
		this.frequency = this.parse_frequency(frequency);
	}

	public double getFrequency(){
		return this.frequency;
	}
	
	public String getFrequencyAsStringInHz(){
		return Double.toString(this.frequency);
	}
	
	public String getFrequencyAsStringInMHz(){
		return Double.toString(this.frequency/1000000);
	}
	
	private double parse_frequency(String frequency) {
		String[] chunks = frequency.split(".");
		double freq = 0;

		freq =  Math.pow(Integer.parseInt(chunks[0]), 6);
		freq += Math.pow(Integer.parseInt(chunks[1]), 3);

		if (chunks[2] != null)
			freq += Integer.parseInt(chunks[2]);

		return freq;
	}
}
